﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SniperScope1 : MonoBehaviour
{
    private void Update()
    {
        if (Input.GetMouseButtonDown(1))
        {
            Camera.main.fieldOfView = 25;
        }
        if (Input.GetMouseButtonUp(1))
        {
            Camera.main.fieldOfView = 70;
        }
    }
}

public class SniperScope : MonoBehaviour
{
    public Camera cam;

    [SerializeField]
    private float[] fovs;

    private int index = 0;

    private void Start()
    {
        cam = GetComponent<Camera>();
    }

    private void Update()
    {
        if (Input.GetMouseButtonDown(1))
        {
            index++;//加索引
            if (index == fovs.Length)//如果超了
            {
                index = 0;
            }
            cam.fieldOfView = fovs[index];
        }
    }
}